這 程式入口點 是任何 Go 應用程式必須的「啟動」序列,由 package main 以及 func main() 區塊所定義。逐步撰寫這些指令的過程稱為 命令式程式設計。
1. 核心定義
- 這 func 關鍵字用來宣告一個函數(一個有命名的程式碼區塊)。
func main()是執行的通用起始行。
2. Go 語法規則
Go 依靠特定的標點符號來理解你的意圖: 引號 用於文字, 括弧 用於傳遞資料,以及 大括號 用於群組邏輯。這個 fmt (格式)套件提供了將輸出列印到主控台所需的工具。
小技巧:打字很重要
請親手輸入程式碼!打錯會導致語法錯誤,而學會修正錯誤是每位開發者不可或缺的重要技能。
main.py
TERMINALbash — 80x24
> Ready. Click "Run" to execute.
>
QUESTION 1
Where does a Go program start its execution?
Inside the import "fmt" statement.
In the func main() function within package main.
At the first line of the fmt package.
Inside the package entry block.
✅ Correct!
Correct! Every executable Go program must have a main package and a main function.❌ Incorrect
Go specifically looks for func main() to begin the execution sequence.QUESTION 2
What primary functionality does the
fmt package provide?Memory management and garbage collection.
Mathematical algorithms and randomization.
Formatting and printing text to the console.
Declaring the entry point of the application.
✅ Correct!
Exactly. Short for 'format', it handles input and output.❌ Incorrect
The fmt package is used for communicating with the external console through formatting.QUESTION 3
Which punctuation is used in Go to group blocks of code together?
Parentheses ( )
Curly Braces { }
Square Brackets [ ]
Double Quotes " "
✅ Correct!
Braces are used to define the scope and body of functions and control structures.❌ Incorrect
Braces {} define code blocks, while parentheses () are generally for data input/functions.QUESTION 4
What is the term for writing down explicit, step-by-step instructions for a computer?
Declarative Programming
Imperative Programming
Functional Formatting
Sequential Scripting
✅ Correct!
Imperative programming is the practice of dictating exact execution paths.❌ Incorrect
The source context defines this specific practice as imperative programming.QUESTION 5
[Short Answer] Which is greater, an "apple" or a "banana"?
Apple
Banana
✅ Correct!
"banana" is greater because it comes later in alphabetical order/Unicode value.❌ Incorrect
In lexicographical comparison, 'b' has a higher value than 'a'.Mission Control: The First Ignition
Entry Point Logic and Syntax Validation
You are at your mission control console (the Go Playground). You need to modify the default greeting and ensure your structural logic (the 'One True Brace Style') is correct to avoid a syntax error.
Q
[Short Answer] Where must opening braces { be placed to avoid syntax errors? (Required Output: 15 words)
Solution:
The opening brace must be placed on the same line as the statement it begins.
The opening brace must be placed on the same line as the statement it begins.
Q
Experiment: playground.go. How do you modify the provided code to greet yourself by name?
Solution:
Change the text between the double quotes in the fmt.Println function to your own name, for example: fmt.Println("Hello, Commander [Name]").
Change the text between the double quotes in the fmt.Println function to your own name, for example: fmt.Println("Hello, Commander [Name]").